package co.yixiang.modules.shop.repository;

import co.yixiang.modules.shop.domain.YxStoreProductCheckmake;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Map;

/**
 * @author frq
 * @date 2020-07-17
 */
public interface YxStoreProductCheckmakeRepository extends JpaRepository<YxStoreProductCheckmake, Integer>, JpaSpecificationExecutor<YxStoreProductCheckmake> {
    @Query(value = "select * from yx_store_product_checkmake where if(?1!='',bar_code like concat('%',?1,'%'),1=1) and if(?2!='',product_name like concat('%',?2,'%'),1=1) and if(?3!='',TO_DAYS(add_time)>=TO_DAYS(?3),1=1) " +
            " and if(?4!='',TO_DAYS(add_time)<=TO_DAYS(?4),1=1) order by add_time desc",
            countQuery = "select count(*) from yx_store_product_checkmake where if(?1!='',bar_code like concat('%',?1,'%'),1=1) and if(?2!='',product_name like concat('%',?2,'%'),1=1) and if(?3!='',TO_DAYS(add_time)>=TO_DAYS(?3),1=1) " +
                    " and if(?4!='',TO_DAYS(add_time)<=TO_DAYS(?4),1=1)", nativeQuery = true)
    Page<Map> findCheckmakeAll(String barCode, String productName, String beginTime, String endTime, Pageable pageable);
}